//功能权限管理
var id;
$(function () {
        id = ly.getUrlParam("id");
        $("#id").val(id);
        //权限分配回显
        var url = site.apiUrl + "/moble/userBriefing/selectUserBriefingById";
        request({
                url: url,
                data: {
                        'id': id,
                },
                type: 'GET',
                ajaxform: true,
                callback: function (r) {
                        if (r.code == "rest.success") {
                                console.log(r)
                                var data = r.result;
                                var html = '';
                                var htmlImg = '';
                                if (data.audioFileUploadList) {
                                        // if (data.audioFileUploadList == '' || data.audioFileUploadList == null) {
                                        //         $('#audio_show').hide()
                                        // }
                                        // if (data.picFileUploadList == '' || data.picFileUploadList == null) {
                                        //         $('#Img_show').hide()
                                        // }
                                        for (let i = 0; i < data.audioFileUploadList.length; i++) {

                                           var audioPath = "'"+data.audioFileUploadList[i].filePath+"'";
                                           var fileName = "'"+data.audioFileUploadList[i].fileName+"'";
                                           html += '<a target="_blank" href="javascript:void(0)" onclick="downloadMp3('+audioPath+','+fileName+')" '+' >录音下载</a> ' +
                                           '<a id="filedown" class="hide" style="visibility: hidden;" target="_black">下载</a>'

                                        }

                                        $('#audio_play').html(html);

                                } else {
                                        $('#audio_show').hide()
                                }


                                if (data.picFileUploadList) {
                                        for (let i = 0; i < data.picFileUploadList.length; i++) {
                                                htmlImg += '<img  src=' + site.gateUrl + data.picFileUploadList[i].filePath + '/>'
                                        }
                                        $('#img-box').html(htmlImg);
                                } else {
                                        $('#Img_show').hide()
                                }
                                var videoData = data.videoFileUploadList;
                                     if(data.videoFileUploadList){
                                          var videoHtml='';
                                          for (let i = 0; i < videoData.length; i++) {
                                               videoHtml+='<video    controls src="'+videoData[i].url+'"></video>'                                                             
                                          }     
                                          $("#videoBox").html(videoHtml);
                                     }   
                                //
                                console.log(data)
                                $('#taskName').val(data.briefingName);
                                $('#taskContent').val(data.briefingContext);
                                $('#taskTime').val(data.creatTime)
                                $('#userNikeName').val(data.userNikeName)
                                // $('#audios').attr("id",site.gateUrl+data.audioFileUploadList[0].filePath)
                        } else {
                                ly.toast(r.result);
                        }
                }
        });



});


// function toggleSound() {
//     var music = document.getElementById("vd");//获取ID  
//         console.log(music);
//         console.log(music.paused);
//     if (music.paused) { //判读是否播放  
//         music.paused=false;
//         music.play(); //没有就播放 
//         }         
// }

// setInterval("toggleSound()",2000);

function down(fileUrl){
        // 这是传统的下载方式
        const downloadFileA = document.createElement('a')
        document.body.append(downloadFileA)
        downloadFileA.href=fileUrl
        downloadFileA.download = '下载文件.csv'
// 超链接 target="_blank" 要增加 rel="noopener noreferrer" 来堵住钓鱼安全漏洞。如果你在链接上使用 target="_blank"属性，并且不加上rel="noopener"属性，那么你就让用户暴露在一个非常简单的钓鱼攻击之下。(摘要)
        downloadFileA.rel = 'noopener noreferrer'
        downloadFileA.click()
        document.body.removeChild(downloadFileA)
}


/**
 * 下载mp3
 * @param audioPath
 */
function downloadMp3(audioPath,fileName) {
        var url = site.apiUrl+"/moble/userEvent/downAudio?audioPath="+audioPath+"&fileName="+fileName;
        $("#filedown").attr("href",url);
        document.getElementById("filedown").click();
        console.log('audioPath:',audioPath);
        console.log('fileName:',fileName);
}